﻿using Business.Service;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcAppWeb.Controllers
{
    public class ModularManageController : BaseDataController
    {
        //
        // GET: /FileManage/

        public ActionResult ModularManage()
        {
            if (Session["UserInfo"] == null) return RedirectToAction("LogOn", "Account");
            else
            {
                AppUserList model = (AppUserList)Session["UserInfo"];
                return View(model);

            }
        }

        ///<summary>
        ///查询模块信息
        ///</summary>
        ///<returns></returns>
        public JsonResult InitJsonResult(string systemID, string modularName)
        {
            string where = "  where 1=1 ";
            int page = int.Parse(Request["page"].ToString());
            int rows = int.Parse(Request["rows"].ToString());
            int total = 0;
            if (systemID != "" && systemID != "0")
            {
                where += " and t1.systemID='" + systemID + "'";
            }
            if (modularName != "" && modularName != "0")
            {
                where += " and t2.modularName='" + modularName + "'";
            }
            where += "and t2.modularname is not null order by systemname";
            var retData = new object();
            BFileManage db = new BFileManage();
            retData = db.GetFileModularAllInfo(page, rows, out total, where).ToList();
            Dictionary<string, object> json = new Dictionary<string, object>();
            json.Add("total", total);
            json.Add("rows", retData);
            return Json(json);
        }



        [HttpPost]
        public string SaveData()
        {
            string sjson = string.Empty;
            AppUserList model = (AppUserList)Session["UserInfo"];
            try
            {
                int systemName = Convert.ToInt32(Request["ssystemName"].ToString()); ;
                string txtModularName = Request["txtModularName"].ToString();
                string fileUrl = Request["txtFileName"].ToString();

                BFileManage bfm = new BFileManage();
                OAFileModular fm = new OAFileModular();
                fm.SYSTEMID = systemName;
                fm.MODULARNAME = txtModularName;
                fm.FILEURL = fileUrl;
                fm.USERCODE = model.USERCODE;
                fm.MODULARSTATUS = "1";

                int n = bfm.InsertFileModular(fm);
                if (n > 0)
                {
                    sjson = "{success:true}";
                }
                else
                {
                    sjson = "{success:false,msg:'新增失败！'}";
                }
            }
            catch (Exception ex)
            {

                sjson = "{success:false,msg:'" + ex.Message + "'}";
            }
            System.Threading.Thread.Sleep(2000);
            return sjson;
        }



    }
}
